package com.panda.business.service;

import com.panda.business.domain.WeChatAccountInfo;
import com.panda.business.mapper.WeChatAccountMapper;
import com.panda.common.utils.DateUtils;
import com.panda.framework.netty.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional // 支持事务
public class WeChatAccountService {

	@Autowired
	private WeChatAccountMapper weChatAccountMapper;


	public WeChatAccountInfo getWeChatAccountByid(Integer id) {
		WeChatAccountInfo user = weChatAccountMapper.findWeChatAccountInfoByid(id);
		return user;
	}
	public WeChatAccountInfo findWeChatAccountInfoByDeviceid(String deviceid) {
		WeChatAccountInfo user = weChatAccountMapper.findWeChatAccountInfoByDeviceid(deviceid);
		return user;
	}
	
	public WeChatAccountInfo findWeChatAccountInfoByWeChatId(String weChatId) {
		WeChatAccountInfo user = weChatAccountMapper.findWeChatAccountInfoByWeChatId(weChatId);
		return user;
	}
 
	public List<WeChatAccountInfo> findWeChatAccountInfo(Integer cid ,Long accountid) {
		return weChatAccountMapper.findWeChatAccountInfo(1,accountid);
	}
	
	public List<WeChatAccountInfo> findWeChatAccountInfoByWeChatIdNotEqualsDeviceid(String wechatid,String deviceid){
		return weChatAccountMapper.findWeChatAccountInfoByWeChatIdNotEqualsDeviceid(wechatid, deviceid);
	}
	
	public void delete(Integer id) {
		weChatAccountMapper.delete(id);
	}
	 
	public void update(WeChatAccountInfo user) {
		weChatAccountMapper.update(user);
	}

	public void updateLogined(WeChatAccountInfo user) {
		weChatAccountMapper.updateLogined(user);
	}
	
	public void updateOnline(WeChatAccountInfo user) {
		weChatAccountMapper.updateOnline(user);
	}
	
	public void updateOnlineLogined(WeChatAccountInfo user) {
		weChatAccountMapper.updateOnlineLogined(user);
	}
 
	/**
	 * 刷新缓存
	 */
	public List<WeChatAccountInfo> refreshCache() {
		List<WeChatAccountInfo> accList = weChatAccountMapper.findAllIsLoginAccountWechatInfo();
		if (null != accList && accList.size() > 0) {
			Constant.accountInfoList = accList;
		}
		return accList;
	}
}
